using UnityEngine;
using System.Collections;

public class HealthBar : MonoBehaviour
{
	//Для показа и скрытия бара
	//public bool showBar;
	//Ширина бара
	//public float barWidth;
	//Высота бара
	//public float barHeight;
	//Хп, которое будет отображаться в баре
	public float health;
	public float healthMax;
	//public GUISkin customSkin;
	public OTSprite HealthBarSample;
	public OTSprite nHealthBar;
	
	private OTSprite me;

	// Use this for initialization
	void Start ()
	{
       me = this.gameObject.GetComponent<OTSprite>();
		//Скрываем бар при старте
//		showBar = false;
//		barWidth = me.size.x*20;
//		barHeight = barWidth/5;
//		showBar = true;
		
				//nBullet = Instantiate(bullet, gun.position + (gun.yVector * (gun.size.y / 2)), gun.rotation); 
	   nHealthBar = (Instantiate(HealthBarSample.gameObject) as GameObject).GetComponent<OTSprite>();
	            // Set bullet's position at approximately the gun's shooting barrel
	   // nHealthBar.position = me.position;
	   // nHealthBar.position.y += me.position;
	          //  nBullet.rotation = gun.rotation;
	}
       
	// Update is called once per frame
	
	void Update ()
	{
		if(nHealthBar){
	   	nHealthBar.position = new Vector2(me.position.x, me.position.y-me.size.y/1.5f);
		}
	}
	public void resize(){
		if(nHealthBar){
		nHealthBar.size = new Vector2(1.0f*health/healthMax,0.1f);//(20f, 200f);
		}
	}
	public void deleteBar(){
		if(nHealthBar){
			Destroy(nHealthBar.gameObject);
		}
	}
       
	/*void OnGUI ()
	{
	    //GUI.skin = customSkin;
		if (showBar) {
			//Debug.Log(me.position.x);
	   		nHealthBar.position = me.position;
	   		//nHealthBar.position.y += me.size.y;
			//Создаём строку, которая будет отображаться в 2 вариантах
			//string str =  "";
			//GUI.Box (new Rect (20*(me.position.y+15) - barWidth / 2, (20*me.position.x+10) - me.size.y*20, barWidth, barHeight), str);
		}
	}*/
}